<template>
  <div>
    <span
      >我是子组件，父传递过来的title是：<strong>{{ title }}</strong></span
    >
    <button @click="changeTitle">修改title</button>
    <hr />
    <div class="count">
      <button @click="handSub">-</button>
      <span>{{ count }}</span>
      <button @click="handAdd">+</button>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    title: String,
    count: Number,
  },
  data() {
    return {
    
    };
  },
  methods: {
    changeTitle() {
      //通过$emit，向父组件发送消息通知
      this.$emit("changeTitle", "修改后的title");
    },
    handSub() {
      this.$emit("changCount", this.count - 1);
      console.log(this);
    },
    handAdd() {
      this.$emit("changCount", this.count+1);
    },
  },
};
</script>

<style scoped>
div {
  background-color: orange;
}
.count span {
  margin: 5px 10px;
}
</style>